package com.gitee.xhs;

import com.gitee.xhs.sampleRecod.transactionRecord.Transaction;
import com.gitee.xhs.sampleRecod.transactionRecord.TransactionBySecondIterator;
import com.gitee.xhs.sampleRecod.transactionRecord.TransactionIterator;
import com.gitee.xhs.sampleRecod.transactionRecord.jmockTool.TransactionLoopOneToTenMockerInterceptor;
import com.gitee.xhs.sampleRecod.transactionRecord.jmockTool.TransactionLoopOneToTwentyMockerInterceptor;
import com.gitee.xhs.sampleRecod.transactionRecord.jmockTool.TransactionLoopTenToTwentyMockerInterceptor;
import com.gitee.xhs.sampleSource.TransactionUnBoundOneSecondSource;
import com.gitee.xhs.sourceIterator.RateLimitedIterator;
import com.gitee.xhs.sourceIterator.SkipRateLimitedIterator;
import com.gitee.xhs.sourceIterator.skipFunction.TransactionSecondTimerSkipper;

import static com.gitee.xhs.enums.OnTimeEnum.*;
import static com.gitee.xhs.enums.RegularEnum.*;
import static com.gitee.xhs.sampleRecod.transactionRecord.jmockTool.TransactionLoopOneToTenMockerInterceptor.LOOP_KEY_TEN;
import static com.gitee.xhs.sampleRecod.transactionRecord.jmockTool.TransactionLoopOneToTwentyMockerInterceptor.LOOP_KEY_TWENTY;


/**
 * @author BigHead
 * @date 2022/7/19 10:32
 * @description OperatorSourceFactory
 */
public class OperatorSourceFactory {

    public static TransactionUnBoundOneSecondSource unBoundLoopOneToTenOneSecondSource() {
        return new TransactionUnBoundOneSecondSource(
                new RateLimitedIterator<>(
                        new TransactionIterator(
                                false,
                                new TransactionLoopOneToTenMockerInterceptor(),
                                null,
                                null,
                                null,
                                true
                        ),
                        null,
                        SECOND,
                        1,
                        REGULAR
                )
        );
    }

    public static TransactionUnBoundOneSecondSource unBoundLoopTenToTwentyOneSecondSource() {
        return new TransactionUnBoundOneSecondSource(
                new RateLimitedIterator<>(
                        new TransactionIterator(
                                false,
                                new TransactionLoopTenToTwentyMockerInterceptor(),
                                null,
                                null,
                                null,
                                true
                        ),
                        null,
                        SECOND,
                        1,
                        REGULAR
                )
        );
    }

    public static TransactionUnBoundOneSecondSource unBoundLoopOneToTwentyOneSecondSource() {
        return new TransactionUnBoundOneSecondSource(
                new RateLimitedIterator<>(
                        new TransactionIterator(
                                false,
                                new TransactionLoopOneToTwentyMockerInterceptor(),
                                null,
                                null,
                                null,
                                true
                        ),
                        LOOP_KEY_TWENTY,
                        MILLISECOND,
                        500,
                        REGULAR
                )
        );
    }

    public static TransactionUnBoundOneSecondSource unBoundLoopOneToTenOneSecondSkipSource(){
        SkipRateLimitedIterator<Transaction, TransactionIterator> skipRateLimitedIterator = new SkipRateLimitedIterator<>(
                new TransactionBySecondIterator(
                        false,
                        new TransactionLoopOneToTenMockerInterceptor(),
                        null,
                        null,
                        null,
                        true,
                        LOOP_KEY_TEN
                ),
                null,
                SECOND,
                1,
                REGULAR
        );

        TransactionSecondTimerSkipper transactionSecondTimerSkipper = new TransactionSecondTimerSkipper(
                LOOP_KEY_TEN
        );
        skipRateLimitedIterator.setCheckSkip(transactionSecondTimerSkipper);
        return new TransactionUnBoundOneSecondSource(
                skipRateLimitedIterator
        );
    }

}
